﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text;

namespace Orderr
{
    [Serializable]
    public class Order : IComparable
    {
        [Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int OrderID { get; set; }
        public int TotalPrice
        {
            get
            {
                int Sum = 0; Action<OrderDetails> getSum = (x => Sum += x.Amo);
                Details.ForEach(getSum);
                return Sum;
            }
            set { }
        }
        public int ClientID { get; set; }
        public virtual Client Client { get; set; }
        public virtual List<OrderDetails> Details { get; set; } = new List<OrderDetails>();
        public Order()
        {
            OrderID = 0;
            Client = null;
            Details = new List<OrderDetails>();
        }
        public Order(int OID, Client clien)
        {
            OrderID = OID;
            //Client = clien;
            ClientID = clien.ClientID;
        }
        public int CompareTo(object obj2)
        {
            Order other = obj2 as Order;
            return OrderID - other.OrderID;
        }
        public override string ToString()
        {
            //string ret = "------------------------------\nOrder id = " + oid + "\nClient : " + client.ToString() + "\ntotal price = " + totalPrice.ToString() + "\nDetails are below:\n";
            string ret = "";
            foreach (OrderDetails x in Details)
            {
                ret += x.ToString();
            }
            return ret;
        }
        public override bool Equals(object obj)
        {
            Order ob = obj as Order;
            return OrderID == ob.OrderID;
        }
        public override int GetHashCode()
        {
            return OrderID;
        }

        /*public String clientt
        {
            get { return client.ToString(); }
        }
        public String details
        {
            get { return ToString(); }
        }*/
    }
}
